package vanillajdk8.tc236;

import java.util.ArrayList;
import java.util.Arrays;

public class BusinessTasks {

    public static void main(String[] args) {
        BusinessTasks bt = new BusinessTasks();
        String task = bt.getTask(new String[]{"1", "2", "3", "4", "5", "6", "7", "8", "9", "10"}, 46);
        System.out.println("Task Selected: " + task);
    }

    public String getTask(String[] list, int n) {
        return getTaskREC(new ArrayList(Arrays.asList(list)), n);
    }

    private String getTaskREC(ArrayList<String> list, int n) {
        if (list.size() == 1) {
            return list.get(0);
        } else {
            int cont = 1;
            int indexAux = 0;
            while (cont < n) {
                indexAux = (indexAux == list.size() - 1) ? 0 : indexAux + 1;
                cont++;
            }
            list.remove(indexAux);
            return getTaskREC(list, n);
        }
    }
}
